import scrapy


class AppSpider(scrapy.Spider):
    name = "app"
    # allowed_domains = ["api.cheshi.com"]
    # start_urls = ["https://api.cheshi.com/services/common/api.php?api=login.Login"]
    def start_requests(self):
        url = 'https://api.cheshi.com/services/common/api.php?api=login.Login'
        data = {
            'act': 'login',
            'mobile': '13049865313',
            'source': 'pc',
            'password': 'A123456',
            'hold_time': 'yes'
        }
        # 登录成功 scrapy会自动把cookies插入链接上
        yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse)

    def parse(self, response):
        # 爬取个人页面
        admin_url = 'https://my.cheshi.com/user/'
        yield scrapy.Request(url=admin_url,callback=self.parse_admin)

    def parse_admin(self,response):
        print(response.text)